package com.swlz.service.impl;

import java.sql.SQLException;

import com.swlz.dao.FictionTypeDAO;
import com.swlz.entity.FictionType;
import com.swlz.exception.CodeException;
import com.swlz.service.FictionTypeService;
import com.swlz.vo.PageVO;

/**
 * <pre>
 * 业务逻辑接口具体实现类
 * 小说类别
 * ClassName : com.swlz.service.impl.FictionTypeServiceImpl
 * Author : swlz
 * E-Mail : 2233875735@qq.com
 * Date : 2020-06-30 03:09:20
 * Version : 1.0
 * Copyright 2020 swlz.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes
 * </pre>
 **/
public class FictionTypeServiceImpl implements FictionTypeService {
	
	private FictionTypeDAO fictionTypeDAO = new FictionTypeDAO();

	@Override
	public int add(FictionType fictionType) throws CodeException {
		try {
			return fictionTypeDAO.insertSelective(fictionType);
		} catch (SQLException e) {
			throw new CodeException(500, "添加小说类别错误",e);
		}
	}

	@Override
	public int update(FictionType fictionType) throws CodeException {
		try {
			return fictionTypeDAO.updateSelective(fictionType);
		} catch (SQLException e) {
			throw new CodeException(501, "修改小说类别错误",e);
		}
	}

	@Override
	public int delete(Long fictionTypeId) throws CodeException {
		try {
			return fictionTypeDAO.deleteById(fictionTypeId);
		} catch (SQLException e) {
			throw new CodeException(502, "删除小说类别错误",e);
		}
	}

	@Override
	public FictionType get(Long fictionTypeId) throws CodeException {
		try {
			return fictionTypeDAO.selectById(fictionTypeId);
		} catch (SQLException e) {
			throw new CodeException(503, "获取小说类别失败",e);
		}
	}

	@Override
	public PageVO<FictionType> page(FictionType fictionType, Integer current, Integer rowMax) throws CodeException {
		try {
			long total = fictionTypeDAO.countByModel(fictionType);
			PageVO<FictionType> page = new PageVO<>(total, current, rowMax);
			return page.setList(fictionTypeDAO.selectByModel(fictionType, page.getOffset(), page.getRowMax()));
		} catch (SQLException e) {
			throw new CodeException(504, "获取小说类别分页数据失败",e);
		}
	}


}
